package com.party.util;

import lombok.extern.slf4j.Slf4j;
import org.im4java.core.*;


@Slf4j
public class Im4JavaUtils {
    /**
     *  window路径 gm
     */
    public static String windowsPath="D:\\GraphicsMagick-1.3.42-Q16";
    /**
     *  linux路径 gm
     */
    public static String linuxPath="/usr/local/GraphicsMagick/bin";

    public static String linuxDesPath="";

    public static void gmAlterImg(String srcPath, String destPath, int width, int height) throws Exception {
        /**
         *  width 设置为之前的10%
         *  height 设置为之前的10%
         */
        if(!System.getProperty("os.name").toLowerCase().contains("windows")){
            destPath="";
        }
        try {
            log.info("源文件路径-----------------------------------------" + srcPath);
            log.info("目标文件路径----------------------------------------" + destPath);
            log.info("目标文件宽------------------------------------------" + width);
            log.info("目标文件高------------------------------------------" + height);
            IMOperation op = new IMOperation();
            op.addImage(srcPath);
            op.resize(width/10, height/10);
            op.quality(75.0);//0 到100  越高清晰度越高
            op.addImage(destPath);
            ConvertCmd convert = new ConvertCmd(true);
            // linux下不要设置此值，不然会报错
            if (System.getProperty("os.name").toLowerCase().contains("windows")) {
                convert.setSearchPath(windowsPath);
            }else{//linux下面这样配置
                log.info("目标文件路径----------------------------------------" + destPath);
                convert.setSearchPath(linuxPath);
            }
            convert.run(op);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }


}

